load TagBlock,EventHeaders

if #msg="Media"
  Gosub TagBlock,"OBJE","Media"
  ShowAll SOUR "Media"
  hideexcess
  
else if #msg="Sources"
  if @count.SOUR+@count.NOTE>0
    newline
    #elabel=local(@tag)
    if @DATE!=""
      #elabel&=" ("&@DATE.user&")"
    endif
    cell static,#elabel
    set width -1 offset 3
    ShowAll NOTE
    ShowAll SOUR
  endif
  hideexcess
  
else if #msg="box"
  ! box is when formatting events like BIRT, DEAT, MARR in main record window
  newline
  cell GroupBox local(@tag)
    !titleposition aboveTop
    width -1

    if @tag!="BIRT"
      newline
      HMoveTo #rightMargin$-#rightSkip-106
      #vloc=#vpos$

      if @tag="DEAT"
        cell CheckBoxEdit,local("Has Died")
        help local("Check if deceased but nothing else known")
      else if @tag="MARR"
        cell CheckBoxEdit,local("Married")
        help local("Check if married but nothing else known")
      else
        cell CheckBoxEdit,local("Occurred")
        if local("<LANG>")="English"
          help "Check if "&local(@tag)&" occurred but nothing else known"
        else
          help local("Check if event occurred but nothing else known")
        endif
      endif
      width 85
      
      VMoveTo #vloc
      #dtype="DEAT"
      #dskip=85
    else
      #dtype="BIRT"
      #dskip=0
    endif
    
    Show DATE #dtype
    #hloc=#hpos$+#dskip
    #vloc=#vpos$
    Show PLAC @tag
    
    if @ADDR!=""
      NewLine 1
      tab 1
      hskip 8
      cell Expression,@ADDR
      set format local("ADDR")&": %!"
      set width -1 border none fontsize 10 height 15
      help local("Click 'info' icon to edit address")
    endif

    ! rest in a child window
    MoveTo #hloc,#vloc
    cell StructuresLink,BirthDeathDetails,@tag
    set border no
    if more
      set image "details_here"
    else
      set image "details"
    endif
    SizeToFit
    set offset 1
    LinkAll all
    #tagKey=@tag&" details"
    help local("Click to edit")&": "&local(#tagKey)
  EndGroup
  
else
  ! This is for event table
  newline

  ! header on first event
  GoSub EventHeaders
  
  #startError="no"
  if length(@contents)>100
    if @tag!="EVEN"
      #startError="yes"
      cell static,"Line 1 of next "&@tag&" should not have this text:"
      sizetofit
      ! this provides place for the data
      cell EditValue
      set Width -1
      help "Move this invalid text to better place (if needed) and change to 'Y' or empty"
      newline
    endif
  endif
  
  ! event name, check box, and date
  if @tag="EVEN"
    if @contents=""
      #eName=@TYPE
      if #eName=""
        #eName=local(@tag)
        cell static,#eName
      else
        cell expression,@TYPE
        localize true
      endif
      set tabwidth 2 alignment center border square
      cellBackground "Table Cell Background"
      set borderColor "Table Cell Background" borderWidth 1
    else
      cell EditValue
      set tabwidth 2
      help local("Enter event description")
    endif
    #startError="omitQuestionMark"
  else
    #eName=local(@tag)
    cell static,#eName
    set tabwidth 2 alignment center border square
    cellBackground "Table Cell Background"
    set borderColor "Table Cell Background" borderWidth 1
  endif

  if @tag!="BIRT"
    ! BIRT has no box, #startError="yes" was first line error
    ! #startError="omitCheckBox" means omit ? too
    if #startError="no"
      tab -2
      hskip 7
      cell CheckBoxEdit
      set tabwidth 1
      if local("<LANG>")="English"
        help "Check if "&local(@tag)&" occurred but nothing else known"
      else
        help local("Check if event occurred but nothing else known")
      endif
    else if @tag!="EVEN"
      tab -2
      hskip 7
      cell static,"?"
      set tabwidth 1 alignment center
    endif
  endif

  show DATE Event
  show PLAC Event

  ! rest in a child window
  cell StructuresLink,EventDetails,@tag
  set border no width -1
  if more
    set image "details_here"
  else
    set image "details"
  endif
  LinkAll all

  #tagKey=@tag&" details"
  help local("Click to edit")&": "&local(#tagKey)
endif
